// pages/syhui/syhui.js

const app = getApp();
Page({
  /**
   * 页面的初始数据
   */
  data: {
    quyuxin: '', //区域名
    openid: '',
    phone: '', //手机号
    CUSTOMER_TEL: '', //手机号
    Getphone: false,
    code: '',
    value1: 0,
    sihuodong: '', //四个活动
    lunbo: [], //轮播
    jincai: '', //精彩活动
    remen: '', //热门活动
    ad_frame: true, //广告框
    CON_VALUE: '', //判断活动显示
    OFFICIALACCOUNTARTICLE: '', //更多
    RILI: [],
    GUANGGAO: '', //公告
    aaa: [{
        ccc: 'https://jiagaojie.oss-cn-beijing.aliyuncs.com/image/hua1.png',
      },
      {
        ccc: 'https://jiagaojie.oss-cn-beijing.aliyuncs.com/image/hua2.png',
      },
      {
        ccc: 'https://jiagaojie.oss-cn-beijing.aliyuncs.com/image/hua3.png',
      },
      {
        ccc: 'https://jiagaojie.oss-cn-beijing.aliyuncs.com/image/hua41.png',
      },

    ],

    SELECTED:'',
    HOT:'',
  },


  youhuiyixia() {
    wx.navigateTo({
      url: '../../pages/shanxiyouhuiyixiadenglu/shanxiyouhuiyixiadenglu',
    })
  },







  



  
  // 跳商城
  qushangcheng() {
    wx.switchTab({
      url: '../../pages/sangcheng/sangcheng',
    })
  },

  // 跳下面的权益
  ququnyi() {
    wx.navigateTo({


      url: '../../pages/tabticket/tabticket',
    })
  },


  


  // 跳转地区
  diqu() {
    wx.navigateTo({
      url: '../../pages/quyu/quyu',
    })
  },


  remenhuodong(e){

    const sb = e.currentTarget.dataset.item.CON_VALUE
    console.log(sb);
    console.log(`../../${sb}`, );
    // this.data.CUSTOMER_TEL
    wx.navigateTo({
      url: `../../${sb}?data=${this.data.CUSTOMER_TEL} `,
    })

  },


  jinpinghuodong(e){

    console.log(e.currentTarget);

    const sb = e.currentTarget.dataset.item.CON_VALUE
    console.log(sb);
    console.log(`../../${sb}`, );
    // this.data.CUSTOMER_TEL
    wx.navigateTo({
      url: `../../${sb}?data=${this.data.CUSTOMER_TEL} `,
    })
  },

















  tiaolian(e) {
    console.log(e);
    if (e.currentTarget.dataset.item.VALID == 1) {

      console.log(e.currentTarget.dataset.item.CON_VALUE);



      // console.log(txtlist);
      // let txtlist = this.data.sihuodong[0].CON_DESC.substring(0, 4);
      // if (txtlist == 'page') {
        const sb = e.currentTarget.dataset.item.CON_VALUE
        console.log(sb);
        console.log(`../../${sb}`, );
        // this.data.CUSTOMER_TEL
        wx.navigateTo({
          url: `../../${sb}?data=${this.data.CUSTOMER_TEL} `,
        })
      // } else {
      //   wx.navigateTo({
      //     url: '../../pages/wangdh/wangdh',
      //   })
      // }




    } else if (e.currentTarget.dataset.item.VALID  == 2) {

      console.log(e.currentTarget.dataset.item.CON_VALUE);



      // console.log(txtlist);
      // let txtlist = this.data.sihuodong[0].CON_DESC.substring(0, 4);
      // if (txtlist == 'page') {
        const sb = e.currentTarget.dataset.item.CON_VALUE
        console.log(sb);
        console.log(`../../${sb}`, );
        // this.data.CUSTOMER_TEL
        wx.navigateTo({
          url: `../../${sb}?data=${e.currentTarget.dataset.item.CON_URL} `,
        })
      // } else {
      //   wx.navigateTo({
      //     url: '../../pages/wangdh/wangdh',
      //   })
      // }




    } else if (e.currentTarget.dataset.item.VALID  == 3) {
      console.log(e.currentTarget.dataset.item.CON_VALUE);

      const sb = e.currentTarget.dataset.item.CON_VALUE
      wx.navigateToMiniProgram({
        shortLink: sb,
        //develop开发版；trial体验版；release正式版
        envVersion: 'release',
        success(res) {
          // 打开成功
          console.log("跳转小程序成功！", res);
        }
      })
      

    } 
  },


  collections() {
    wx.request({
      url: app.globalData.interface+'/newVersion/API_2031_indexData',
      // url: 'http://192.168.3.173:8081/newVersion/API_2031_indexData',
      method: 'POST',
      data: {
        OPEN_ID: this.data.openid, //用户OPEN_ID
        session_key: this.data.session_key,
        OPEN_UUID: this.data.jiami
      },
      header: {
        'content-type': 'application/x-www-form-urlencoded'
      },

      success: res => {
        console.log(res);
        // console.log(res.data.HOMEPAGELOTTERY[0].CON_VALUE);
        // console.log(res.data.OFFICIALACCOUNTARTICLE[0].CON_VALUE);
        this.setData({
          sihuodong: res.data.TOPSIX, //四个活动
          lunbo: res.data.INDEXBANNER, //轮播
          remen: res.data.HOTACTIVITY, //热门活动
          jincai: res.data.WONDERFUL, //精彩活动
          CON_VALUE: res.data.HOMEPAGELOTTERY[0].CON_VALUE, //判断活动显示
          OFFICIALACCOUNTARTICLE: res.data.OFFICIALACCOUNTARTICLE[0].CON_VALUE, //判断活动显示
          RILI: res.data.RILI,
          GUANGGAO: res.data.GUANGGAO[0].CON_DESC //头条公告
        })
        if (res.data.HOMEPAGELOTTERY[0].CON_VALUE == 'on') {
          this.setData({
            ad_frame: false,
          })
        }
      }
    })
  },


















//页面模块
  yemianmokuai() {
    this.setData({

      CON_CODE: app.globalData.chenshiID,
    });

    console.log(this.data.CON_CODE);

    wx.request({
      url: app.globalData.interface+'/newVersion/API_2033_ALLDEMOData',
      // url: 'http://192.168.3.173:8081/newVersion/API_2031_indexData',
      method: 'POST',
      data: {
        CON_CODE:app.globalData.chenshiID, //用户OPEN_ID

      },
      header: {
        'content-type': 'application/x-www-form-urlencoded'
      },

      success: res => {
        console.log(res);
        console.log(res.data.HOT);

        this.setData({
          HOT:res.data.HOT,
          SELECTED:res.data.SELECTED,
        })

      }
    })
  },































  


  baocunphone() {
    wx.request({
      url: app.globalData.interface+'/newVersion/API_2011_savePhoneAndOpenId',
      method: 'POST',
      //向后端发送的数据
      data: {
        CUSTOMER_TEL: this.data.phone,
        OPEN_ID: this.data.openid,
        KEY: 'xianjgjKey9999',
        OPEN_ID: this.data.openid, //用户OPEN_ID
        session_key: this.data.session_key,
        OPEN_UUID: this.data.jiami
      },
      header: {
        "Content-Type": "application/x-www-form-urlencoded" //POST方式是这个
      },
      success: res => {
        console.log(res);
      }
    })
  },




 



  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(e) {

    console.log(e);

    setTimeout(() => {
      this.setData({
        phone: app.globalData.phone,
        jiami: app.globalData.jiami,
        OPEN_ID: app.globalData.openid,
        openid: app.globalData.openid,
        session_key: app.globalData.session_key,

     
      })
  
    },1000) 


    this.collections()
  
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

    this.setData({
      quyuxin: app.globalData.quyuxin,
    
    });

    this.yemianmokuai()
  },





  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})